---
sidebar_position: 1
title: Guide - Dispatching
sidebar_label: Dispatching
---

# Dispatching

---

### Trigger request

We can execute queries using the built-in `send()` function or use React hooks.

```tsx
import { postLogin } from "server/auth";

...

const handleLogin = async (values: {email: string, password: string}) => {
  const { data, error, status } = await postLogin.setData(values).send();

  if(data) {
    // perform login
    ...
  } else {
    // handle error
    ...
  }

}

...

```

### Method `send()`

The send method takes full advantage of the potential of our features. We have implemented `debouncing`, `retries`,
`cancellation` and `offline awaiting` solutions.

We can also dynamically transfer data to execute the request.

```tsx
import { postData } from "server/auth";

...

const handleSend = async (values: ValuesType) => {
  const { data, error, status } = await postData.send({
    data: values,
    params: { accountId: 2 },
    queryParams: { param1: "test", param2: [1,2,3] }
  })

  if(data) {
    // perform success action
    ...
  } else {
    // handle error
    ...
  }

}

...

```

### Lifecycle

`send()` method allow us to hook into request lifecycle. We can do it with one of following methods.

(@import HyperFetch FetchSendActionsType type=type=type=preview)

#### Example

```ts
const { data, error, status } = await getData.send({
  onSettle: (requestId) => {
    console.log(`Starting request: ${requestId}`);
  },
  onDownloadProgress: (values) => {
    console.log(`Download progress: ${values}`);
  },
  onResponse: (response) => {
    console.log(`Got response: ${response}`);
  },
});
```
